var graph = argument0;
var cell = argument1;
var dir = argument2;
var spacing = argument3;

var length = 0;

var height = array_height_2d(graph);
var width  = array_length_2d(graph, 0);
if (dir == 0)
{
    var next = 0;
    next[0] = cell[0];
    next[1] = cell[1] + 1;
    while (next[1] < width && !graph[next[0], next[1]] && length < spacing)
    {
        length++;
        next[1]++;
    }
}
else if (dir == 1)
{
    var next = 0;
    next[0] = cell[0] - 1;
    next[1] = cell[1];
    while (next[0] > -1 && !graph[next[0], next[1]] && length < spacing)
    {
        length++;
        next[0]--;
    }
}
else if (dir == 2)
{
    var next = 0;
    next[0] = cell[0];
    next[1] = cell[1] - 1;
    while (next[1] > -1 && !graph[next[0], next[1]] && length < spacing)
    {
        length++;
        next[1]--;
    }
}
else if (dir == 3)
{
    var next = 0;
    next[0] = cell[0] + 1;
    next[1] = cell[1];
    while (next[0] < height && !graph[next[0], next[1]] && length < spacing)
    {
        length++;
        next[0]++;
    }
}
return length == spacing;